
<!-- 客户列表 -->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="日期查询" prop="createTime">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客户名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户级别" prop="customerRank">
        <el-select
          v-model="queryParams.customerRank"
          placeholder="请选择客户级别"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in dict.type.customer_rank"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="客户状态" prop="customerStatus">
        <el-select
          v-model="queryParams.customerStatus"
          placeholder="请选择客户状态"
          clearable
          size="small"
        >
          <!-- <el-option v-for="dict in dict.type.customer_status" :key="dict.value" :label="dict.label" :value="dict.value" /> -->
          <el-option label="意向客户" value="意向客户"></el-option>
          <el-option label="制样客户" value="制样客户"></el-option>
          <el-option label="成交客户" value="成交客户"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['crm:customer:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-refresh-right"
          size="mini"
          :disabled="!selected"
          @click="handleToPool"
          v-hasPermi="['crm:customer:toPool']"
          >移入公海</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-s-promotion"
          size="mini"
          :disabled="!selected"
          @click="handleTransfer"
          v-hasPermi="['crm:customer:transfer']"
          >转移客户</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
          v-hasPermi="['crm:customer:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport_"
          v-hasPermi="['crm:customer:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="customerList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="80"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="客户名称"
        align="left"
        prop="name"
        :show-overflow-tooltip="true"
        width="200"
      />
      <!-- <el-table-column
        label="地区"
        align="center"
        prop="region"
        :show-overflow-tooltip="true"
      /> -->
      <el-table-column
        label="联系人"
        align="center"
        prop="linkman"
        :show-overflow-tooltip="true"
        width="200"
      />
      <el-table-column
        label="联系电话"
        align="center"
        prop="phone"
        :show-overflow-tooltip="true"
         width="200"
      />
      <el-table-column
        label="地区"
        align="center"
        prop="region"
        :show-overflow-tooltip="true"
         width="220"
      />
      <!-- <el-table-column
        label="客户级别"
        align="center"
        prop="customerRank"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="客户行业"
        align="center"
        prop="customerIndustry"
        :show-overflow-tooltip="true"
      /> -->
      <el-table-column label="成交状态" align="center" prop="dealStatus"  width="160">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.deal_status"
            :value="scope.row.dealStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="最新跟进记录"
        align="center"
        prop="lastUpdateRecord"
        :show-overflow-tooltip="true"
         width="240"
      />
      <el-table-column
        label="负责人"
        align="center"
        prop="owner"
        :show-overflow-tooltip="true"
         width="160"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        align="left"
        class="small-padding"
        width="350px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit-outline"
            @click="handleComment(scope.row)"
            v-hasPermi="['crm:customer:followup']"
            >写跟进</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-promotion"
            @click="handleTransfer(scope.row)"
            v-hasPermi="['crm:customer:transfer']"
            >转移</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['crm:customer:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate_(scope.row)"
            v-hasPermi="['crm:customer:edit']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['crm:customer:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="open"
      width="680px"
      append-to-body

    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        style="height: 500px; overflow-y: auto"
        :disabled="title == '详情'"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入客户名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户编号" prop="code">
              <!-- <el-input
                v-model="form.code"
                :disabled="title === '修改客户' ? true : false"
                placeholder="请输入客户编号"
              /> -->
              <el-input v-model="form.code" placeholder="请输入客户编号"  disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人" prop="linkman">
              <el-input v-model="form.linkman" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="地区" prop="region">
              <Cascader @provincesValueChang="provincesValueChang" :value="form.region" style="width: 100%;"></Cascader>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="客户行业" prop="customerIndustry">
              <el-select
                v-model="form.customerIndustry"
                placeholder="请选择客户行业"
                style="width: 100%"

              >
                <el-option
                  v-for="dict in dict.type.customer_industry"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户级别" prop="customerRank">
              <el-select
                v-model="form.customerRank"
                placeholder="请选择客户级别"
                style="width: 100%"

              >
                <el-option
                  v-for="dict in dict.type.customer_rank"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户状态" prop="customerStatus">
              <el-select
                v-model="form.customerStatus"
                placeholder="请选择客户状态"
                style="width: 100%"

              >
                <el-option label="意向客户" value="意向客户"></el-option>
                <el-option label="制样客户" value="制样客户"></el-option>
                <el-option label="成交客户" value="成交客户"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成交状态" prop="dealStatus">
                    <el-select v-model="form.dealStatus" placeholder="请选择客户状态" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.deal_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="customerRank">
              <el-select v-model="form.dfsCluesStatus" placeholder="请选择状态" style="width: 100%">
                <el-option label="创建" :value="1"></el-option>
                <el-option label="生效" :value="2"></el-option>
                <el-option label="停用" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="负责人" prop="userName">
              <el-select
                v-model="form.userName"
                filterable
                placeholder="请选择负责人"
                style="width: 100%"
              >
                <el-option
                  v-for="(v, i) in userList"
                  :key="i"
                  :label="v.nickName"
                  :value="v.userName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col
            :span="5"
            v-if="
              form.customerStatus === '制样客户' ||
              form.customerStatus === '成交客户'
            "
          >
            <el-form-item label="附件：" prop="url">
              <el-button
                type="primary"
                @click="handleUpload"
                style="width: 70px; font-size: 14px"
                >上传</el-button
              >
              <input
                type="file"
                ref="fileInput"
                style="display: none"
                @change="handleFileChange"
              />
            </el-form-item>
          </el-col>

          <el-col
            :span="8"
            style="margin-left: -50px"
            v-if="
              form.customerStatus === '制样客户' ||
              form.customerStatus === '成交客户'
            "
          >
            <el-form-item label="" prop="">
              <el-link
                type="primary"
                @click="handledownload_"
                v-if="form.url == null"
                style="font-size: 12px"
                :underline="false"
                >下载客户定期评估模板</el-link
              >
              <el-link
                type="primary"
                @click="handledownload_"
                 v-if="form.url != null"
                style="font-size: 12px"
                :underline="false"
                >查看客户定期评估表</el-link
              >
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>

        <!-- <el-form-item label="审核状态" prop="toExamine" v-if="title == '修改客户'&&(form.customerStatus === '制样客户' || form.customerStatus === '成交客户')">
          <el-select v-model="form.toExamine" placeholder="请选择">
                <el-option label="未审核" :value="1"></el-option>
                <el-option label="已审核" :value="2"></el-option>
              </el-select>
        </el-form-item> -->

        <!-- tabs -->

        <el-tabs
          v-model="activeName"
          type="border-card"
          @tab-click="handleClick"
          v-if="title != '添加客户'"
           
        >


          <el-tab-pane label="基本信息" name="基本信息" >
            <div>
              <el-row>
                <el-col :span="11">
                  <!-- <el-form-item
                    label="税号"
                    prop="taxNumber"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="税号"
                    prop="taxNumber"
                    label-width="90px"
                  > 
                    <el-input v-model="form.taxNumber" />
                  </el-form-item>
                </el-col>
                <el-col :span="11" :offset="1">
                  <!-- <el-form-item
                    label="负责人"
                    prop="responsiblePerson"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="负责人"
                    prop="responsiblePerson"
                    label-width="90px"
                  >
                    <el-input v-model="form.responsiblePerson" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="10">
                  <!-- <el-form-item
                    label="总公司"
                    prop="headOffice"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="总公司"
                    prop="headOffice"
                    label-width="90px"
                  >
                    <el-input v-model="form.headOffice" />
                  </el-form-item>
                </el-col>
                <el-col :span="10" :offset="4">
                  <!-- <el-form-item
                    label="必选"
                    prop="headOfficePayment"
                    label-width="50px"
                    :rules="[
                      { required: true, message: '请选择', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="选择"
                    prop="headOfficePayment"
                    label-width="36px"
                  >
                    <el-row>
                      <el-col :span="12">
                        <el-radio v-model="form.headOfficePayment" label="是"
                          >总公司付款</el-radio
                        >
                      </el-col>
                      <el-col :span="12">
                        <el-radio v-model="form.headOfficePayment" label="否"
                          >寄售客户</el-radio
                        >
                      </el-col>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="9">
                  <div>
                    交易对象分类方式
                    <!-- <el-form-item
                      label="渠道"
                      prop="channel"
                      label-width="70px"
                      :rules="[
                        { required: true, message: '必填', trigger: 'blur' },
                      ]"
                    > -->
                    <el-form-item
                      label="渠道"
                      prop="channel"
                      label-width="70px"
                    >
                      <el-input v-model="form.channel" />
                    </el-form-item>
                    <!-- <el-form-item
                      label="类型"
                      prop="type"
                      label-width="70px"
                      :rules="[
                        { required: true, message: '必填', trigger: 'blur' },
                      ]"
                    > -->
                    <el-form-item
                      label="类型"
                      prop="type"
                      label-width="70px"
                    >
                      <el-input v-model="form.type" />
                    </el-form-item>
                    <el-form-item label="地区" prop="region" label-width="70px">
                      <Cascader
                        @provincesValueChang="provincesValueChang"
                        :value="form.region"
                        style="width: 100%"
                      ></Cascader>
                    </el-form-item>
                    <!-- <el-form-item
                      label="国家"
                      prop="country"
                      label-width="70px"
                      :rules="[
                        { required: true, message: '必填', trigger: 'blur' },
                      ]"
                    > -->
                    <el-form-item
                      label="国家"
                      prop="country"
                      label-width="70px"
                    >
                      <el-input v-model="form.country" />
                    </el-form-item>
                    <!-- <el-form-item
                      label="路线"
                      prop="route"
                      label-width="70px"
                      :rules="[
                        { required: true, message: '必填', trigger: 'blur' },
                      ]"
                    > -->
                    <el-form-item
                      label="路线"
                      prop="route"
                      label-width="70px"
                    >
                      <el-input v-model="form.route" />
                    </el-form-item>
                    <!-- <el-form-item
                      label="其他"
                      prop="other"
                      label-width="70px"
                      :rules="[
                        { required: true, message: '必填', trigger: 'blur' },
                      ]"
                    > -->
                    <el-form-item
                      label="其他"
                      prop="other"
                      label-width="70px"
                    >
                      <el-input v-model="form.other" />
                    </el-form-item>
                  </div>
                </el-col>
                <el-col :span="12" style="margin-top: 20px" :offset="2">
                  <!-- <el-form-item
                    label="开户银行"
                    prop="openingBank"
                    label-width="110px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="开户银行"
                    prop="openingBank"
                    label-width="110px"
                  >
                    <el-input v-model="form.openingBank" />
                  </el-form-item>
                  <!-- <el-form-item
                    label="银行账号"
                    prop="bankAccount"
                    label-width="110px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="银行账号"
                    prop="bankAccount"
                    label-width="110px"
                  >
                    <el-input v-model="form.bankAccount" />
                  </el-form-item>
                  <el-form-item
                    label="付款银行（二）"
                    prop="paymentBank2"
                    label-width="110px"
                  >
                    <el-input v-model="form.paymentBank2" />
                  </el-form-item>
                  <el-form-item
                    label="银行账号（二）"
                    prop="bankAccount2"
                    label-width="110px"
                  >
                    <el-input v-model="form.bankAccount2" />
                  </el-form-item>
                  <el-form-item
                    label="付款银行（三）"
                    prop="paymentBank3"
                    label-width="110px"
                  >
                    <el-input v-model="form.paymentBank3" />
                  </el-form-item>
                  <el-form-item
                    label="银行账号（三）"
                    prop="bankAccount3"
                    label-width="110px"
                  >
                    <el-input v-model="form.bankAccount3" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="11">
                  <!-- <el-form-item
                    label="业务人员"
                    prop="businessPerson"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="业务人员"
                    prop="businessPerson"
                    label-width="90px"
                  >
                    <el-input v-model="form.businessPerson" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="开业日期"
                    prop="establishmentDate"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->

                  <el-form-item
                    label="开业日期"
                    prop="establishmentDate"
                    label-width="90px"
                  >
                    <el-date-picker
                      v-model="form.establishmentDate"
                      type="datetime"
                      placeholder="选择开业时间"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="11">
                  <!-- <el-form-item
                    label="收款业务员"
                    prop="collectionPerson"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="收款业务员"
                    prop="collectionPerson"
                    label-width="90px"
                  >
                    <el-input v-model="form.collectionPerson" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="停业日期"
                    prop="closedDate"
                    label-width="90px"
                  >
                    <el-date-picker
                      v-model="form.closedDate"
                      type="datetime"
                      placeholder="选择停业时间"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="11">
                  <!-- <el-form-item
                    label="部门"
                    prop="department"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="部门"
                    prop="department"
                    label-width="90px"
                  >
                    <el-input v-model="form.department" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="员工人数"
                    prop="numberOfEmployees"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="员工人数"
                    prop="numberOfEmployees"
                    label-width="90px"
                  >
                    <el-input v-model="form.numberOfEmployees" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="11">
                  <!-- <el-form-item
                    label="注册资金"
                    prop="registeredCapital"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="注册资金"
                    prop="registeredCapital"
                    label-width="90px"
                  >
                    <el-input v-model="form.registeredCapital" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="分店数"
                    prop="numberOfBranches"
                    label-width="90px"
                  >
                    <el-input v-model="form.numberOfBranches" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="11">
                  <!-- <el-form-item
                    label="年营业额"
                    prop="annualRevenue"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="年营业额"
                    prop="annualRevenue"
                    label-width="90px"
                  >
                    <el-input v-model="form.annualRevenue" />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-tab-pane>
          <el-tab-pane label="地址信息" name="地址信息" >
            <div>
              <el-row>
                <el-col :span="8">
                  <!-- <el-form-item
                    label="联系人"
                    prop="contactPerson"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="联系人"
                    prop="contactPerson"
                    label-width="90px"
                  >
                    <el-input v-model="form.contactPerson" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item
                    label="TEL_NO(一)"
                    prop="telNo1"
                    label-width="90px"
                  >
                    <el-input v-model="form.telNo1" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="FAX NO" prop="faxNo" label-width="90px">
                    <el-input v-model="form.faxNo" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="E-Mail"
                    prop="email"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="E-Mail"
                    prop="email"
                    label-width="90px"
                  >
                    <el-input v-model="form.email" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="TEL_NO(二)"
                    prop="telNo2"
                    label-width="90px"
                  >
                    <el-input v-model="form.telNo2" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="邮编"
                    prop="postalCode"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->

                  <el-form-item
                    label="邮编"
                    prop="postalCode"
                    label-width="90px"
                  >
                    <el-input v-model="form.postalCode" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="手机"
                    prop="mobilePhone"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="手机"
                    prop="mobilePhone"
                    label-width="90px"
                  >
                    <el-input v-model="form.mobilePhone" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="24">
                  <!-- <el-form-item
                    label="注册地址"
                    prop="registeredAddress"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="注册地址"
                    prop="registeredAddress"
                    label-width="90px"
                  >
                    <el-input v-model="form.registeredAddress" />
                  </el-form-item>
                </el-col>
              </el-row>

<!-- 2.0寸金 版本 删除后面两个邮编 留第一个邮编 -->
              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="邮编"
                    prop="postalCode2"
                    label-width="90px"
                  >
                    <el-input v-model="form.postalCode2" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="24">
                  <!-- <el-form-item
                    label="发票地址"
                    prop="invoiceAddress"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="发票地址"
                    prop="invoiceAddress"
                    label-width="90px"
                  >
                    <el-input v-model="form.invoiceAddress" />
                  </el-form-item>
                </el-col>
              </el-row>


              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="邮编"
                    prop="postalCode3"
                    label-width="90px"
                  >
                    <el-input v-model="form.postalCode3" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="24">
                  <!-- <el-form-item
                    label="运货地址"
                    prop="deliveryAddress"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="运货地址"
                    prop="deliveryAddress"
                    label-width="90px"
                  >
                    <el-input v-model="form.deliveryAddress" />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-tab-pane>
          <el-tab-pane label="交易信息" name="交易信息">
            <div>
              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="交易币种"
                    prop="transactionCurrency"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="交易币种"
                    prop="transactionCurrency"
                    label-width="90px"
                  >
                    <el-input v-model="form.transactionCurrency" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="账款科目"
                    prop="billSubject"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="账款科目"
                    prop="billSubject"
                    label-width="90px"
                  >
                    <el-input v-model="form.billSubject" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="定价顺序"
                    prop="pricingOrder"
                    label-width="90px"
                  >
                    <el-input v-model="form.pricingOrder" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="折扣率"
                    prop="discountRate"
                    label-width="90px"
                  >
                    <el-input v-model="form.discountRate" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="预收科目"
                    prop="advanceSubject"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="预收科目"
                    prop="advanceSubject"
                    label-width="90px"
                  >
                    <el-input v-model="form.advanceSubject" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="开票日期"
                    prop="invoiceDate"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="开票日期"
                    prop="invoiceDate"
                    label-width="90px"
                  >
                    <template>
                      每月
                      <el-input
                        v-model="form.invoiceDate"
                        style="width: 40px; margin: 0 7px"
                      />
                      日
                    </template>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="发票种类"
                    prop="invoiceType"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="发票种类"
                    prop="invoiceType"
                    label-width="90px"
                  >
                    <el-select v-model="form.invoiceType" placeholder="请选择">
                      <el-option
                        v-for="item in options_invoiceType"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="票据科目"
                    prop="accountSubject"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="票据科目"
                    prop="accountSubject"
                    label-width="90px"
 
                  >
                    <el-input v-model="form.accountSubject" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="税种"
                    prop="taxType"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="税种"
                    prop="taxType"
                    label-width="90px"
                  >
                    <el-select v-model="form.taxType" placeholder="请选择">
                      <el-option
                        v-for="item in options_taxType"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <!-- <el-form-item
                    label="付款条件"
                    prop="paymentTerms"
                    label-width="90px"
                    :rules="[
                      { required: true, message: '必填', trigger: 'blur' },
                    ]"
                  > -->
                  <el-form-item
                    label="付款条件"
                    prop="paymentTerms"
                    label-width="90px"
                  >
                    <el-input v-model="form.paymentTerms" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="价格说明"
                    prop="priceDescription"
                    label-width="90px"
                  >
                    <el-input v-model="form.priceDescription" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="单据发送方式"
                    prop="documentDeliveryMethod"
                    label-width="110px"
                  >
                    <el-select
                      v-model="form.documentDeliveryMethod"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in options_documentDeliveryMethod"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="销售评级"
                    prop="salesRating"
                    label-width="90px"
                  >
                    <el-input v-model="form.salesRating" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="结算方式"
                    prop="settlementMethod"
                    label-width="90px"
                  >
                    <el-input v-model="form.settlementMethod" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="初次交易"
                    prop="firstTransaction"
                    label-width="90px"
                  >
                    <el-date-picker
                      v-model="form.firstTransaction"
                      type="datetime"
                      placeholder="选择初次交易时间"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="票据寄领"
                    prop="billCollection"
                    label-width="90px"
                  >
                    <el-select
                      v-model="form.billCollection"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in options_billCollection"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="最近交易"
                    prop="latestTransaction"
                    label-width="90px"
                  >
                    <el-date-picker
                      v-model="form.latestTransaction"
                      type="datetime"
                      placeholder="选择最近交易时间"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="订金比率"
                    prop="depositRate"
                    label-width="90px"
                  >
                    <el-input v-model="form.depositRate" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="分期收款条件"
                    prop="installmentCollectionTerms"
                    label-width="100px"
                  >
                    <el-input v-model="form.installmentCollectionTerms" />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-tab-pane>
          <el-tab-pane label="信用信息" name="信用信息">
            <div>
              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label=""
                    prop="headOfficeControl"
                    label-width="90px"
                  >
                    <el-checkbox
                      v-model="form.headOfficeControl"
                      label="信用额度由总公司控制"
                      size="large"
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item
                    label="信用评级"
                    prop="creditRating"
                    label-width="90px"
                  >
                    <el-input
                      v-model="form.creditRating"
                      style="width: 40px; margin: 0 7px"
                    />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="信用额度控制"
                    prop="limitControl"
                    label-width="90px"
                  >
                    <!-- <el-select v-model="form.limitControl" placeholder="请选择">
                      <el-option
                        v-for="item in options_invoiceType"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select> -->

                    <el-input v-model="form.limitControl" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="RMB 信用额度"
                    prop="creditLimit"
                    label-width="100px"
                  >
                    <el-input v-model="form.creditLimit" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="     可超出率"
                    prop="exceedingRate"
                    label-width="100px"
                  >
                    <el-input v-model="form.exceedingRate" />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <div>
                    订单审核时，信用超额处理方式
                    <el-form-item
                      label=""
                      prop="orderExcessHandlingMethod"
                      label-width="50px"
                    >
                      <el-row>
                        <el-col :span="8">
                          <el-radio
                            v-model="form.orderExcessHandlingMethod"
                            label="0"
                            >不检查</el-radio
                          >
                        </el-col>
                        <el-col :span="8">
                          <el-radio
                            v-model="form.orderExcessHandlingMethod"
                            label="1"
                            >警告</el-radio
                          >
                        </el-col>
                        <el-col :span="8">
                          <el-radio
                            v-model="form.orderExcessHandlingMethod"
                            label="2"
                            >拒绝</el-radio
                          >
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <div>
                    销货单审核时，信用超额处理方式
                    <el-form-item
                      label=""
                      prop="saleLipExcessHandlingMethod"
                      label-width="50px"
                    >
                      <el-row>
                        <el-col :span="8">
                          <el-radio
                            v-model="form.saleLipExcessHandlingMethod"
                            label="0"
                            >不检查</el-radio
                          >
                        </el-col>
                        <el-col :span="8">
                          <el-radio
                            v-model="form.saleLipExcessHandlingMethod"
                            label="1"
                            >警告</el-radio
                          >
                        </el-col>
                        <el-col :span="8">
                          <el-radio
                            v-model="form.saleLipExcessHandlingMethod"
                            label="2"
                            >拒绝</el-radio
                          >
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <div>
                    检查比率
                    <el-form-item
                      label="未兑现应收票据比率"
                      prop="collectionRatio"
                      label-width="120px"
                    >
                      <el-input v-model="form.collectionRatio" />
                    </el-form-item>

                    <el-form-item
                      label="应收账款比率"
                      prop="accountsReceivableRatio"
                      label-width="120px"
                    >
                      <el-input v-model="form.accountsReceivableRatio" />
                    </el-form-item>

                    <el-form-item
                      label="未开票销货金额比率"
                      prop="inventorySaleOrderRatio"
                      label-width="120px"
                    >
                      <el-input v-model="form.inventorySaleOrderRatio" />
                    </el-form-item>

                    <el-form-item
                      label="未出货订单金额比率"
                      prop="shippingOrderRatio"
                      label-width="120px"
                    >
                      <el-input v-model="form.shippingOrderRatio" />
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
            </div>
          </el-tab-pane>
          <el-tab-pane label="证照信息" name="证照信息">
            <div>
              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="营业执照"
                    prop="businessLicense "
                    label-width="90px"
                  >
                    <el-button
                      type="primary"
                      @click="handleUploadBusinessLicense"
                      style="width: 70px; font-size: 14px"
                      >上传</el-button
                    >

                    <input
                      type="file"
                      ref="fileInputBusinessLicense"
                      style="display: none"
                      @change="handleFileChangeBusinessLicense"
                    />
                    <el-link
                      type="primary"
                      @click="handledownload_yingye"
                      v-if="form.businessLicense != null"
                      style="font-size: 12px;margin-left: 20px;"
                      :underline="false"
                      >查看营业执照
                    </el-link>
                  </el-form-item>

                </el-col>


              </el-row>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="review()" v-if="title == '修改客户'&&(form.customerStatus === '制样客户' || form.customerStatus === '成交客户')&&this.id_guanli==true">审核</el-button>   -->
        <el-button type="primary" 
        @click="review()" 
        v-if="title == '修改客户'&&(form.customerStatus === '制样客户' || form.customerStatus === '成交客户')&&this.id_guanli==true">
        {{ this.form.toExamine||'审核' }}
      </el-button>  
       
       
        <el-button type="primary" @click="submitForm" v-if="this.title != '详情'">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <TransferCustomerComponent
      v-if="transferCustomer"
      ref="transferCustomer"
      @close-dialog="handleTransferCustomerClose"
    />
    <ToPoolComponent
      v-if="toPool"
      ref="toPool"
      @close-dialog="handleToPoolClose"
    />
    <CommentComponent
      v-if="commentCustomer"
      ref="commentCustomer"
      @close-dialog="handleCommentClose"
    />
  </div>
</template>

<script>
import {
  listCustomer,
  getCustomer,
  delCustomer,
  addCustomer,
  updateCustomer,
  handledownloadApi,
  reqFileUpload,
  reqFileDownload,
  getreview
} from "@/api/crm/customer";
import { download } from '@/utils/request'
import {
  toCustomer_before2,
  toCustomer_before1,
} from '@/api/crm/clues'
import { reqUserList } from "@/api/crm/clues";
import TransferCustomerComponent from "./Transfer";
import ToPoolComponent from "./ToPool";
import CommentComponent from "./Comment";
import Cascader from "@/components/Cascader/index.vue";
import { reqSendToken } from "@/api/login.js";
import { getUserInfoByToken } from "@/utils/toosls.js";
import axios from "axios";
export default {
  name: "Customer",
  components: {
    TransferCustomerComponent,
    ToPoolComponent,
    CommentComponent,
    Cascader,
  },
  dicts: [
    "clues_source",
    "customer_industry",
    "clues_status",
    "customer_rank",
    "region_list",
    "customer_status",
    "deal_status",
  ],
  data() {
    return {
      Row: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 非勾选禁用
      selected: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        linkman: null,
        phone: null,
        region: null,
        customerIndustry: null,
        customerRank: null,
        customerStatus: null,
        cluesName: null,
        cluesSource: null,
        cluesStatus: null,
        owner: null,
         id_:'',
         id_guanli:'',
         code_:''
      },
      // 表单参数
      form: {
        headOfficePayment: "否",
        consignmentCustomer: false,
        toExamine: "审核",
        orderExcessHandlingMethod: "0",
        saleLipExcessHandlingMethod: "0",
        headOfficeControl: false,
        businessLicense: "",
        url: "",
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "客户名称不能为空", trigger: "blur" },
        ],
        linkman: [
          { required: true, message: "联系人不能为空", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
        ],

        userName: [
          { required: true, message: "负责人不能为空", trigger: "blur" },
        ],
        url: [
          // { required: true, message: '文件上传不能为空', trigger: 'blur' },
          { required: true, message: "必填", trigger: "blur" },
        ],
      },
      transferCustomer: false,
      toPool: false,
      commentCustomer: false,
      userList: [],
      activeName: "基本信息",
      options_invoiceType: [
        { value: "选项1", label: "A:专用发票" },
        { value: "选项2", label: "B:增值税普通发票" },
        { value: "选项3", label: "C:服务型发票" },
        { value: "选项4", label: "D:其他" },
      ],
      options_taxType: [
        { value: "选项1", label: "1:应税内含" },
        { value: "选项2", label: "2:应税外加" },
        { value: "选项3", label: "3:零税率" },
        { value: "选项4", label: "4:免税" },
        { value: "选项5", label: "9:不计税" },
      ],
      options_documentDeliveryMethod: [
        { value: "选项1", label: "1:邮寄" },
        { value: "选项2", label: "2:FAX" },
        { value: "选项3", label: "3:EDI" },
        { value: "选项4", label: "4:E-MAIL" },
      ],
      options_billCollection: [{ value: "选项1", label: "1:邮寄" }],
    };
  },
  created() {
    this.getList();
    this.getUserList();
    this.getUserInfo()
  },
  methods: {

    getcuscode(){
    toCustomer_before1().then((res) => {
            console.log(res.data.data[0].id, "===发送第一个请求,获取到id===");
            this.id_ = +res.data.data[0].id;
            console.log(this.id_, "===this.id_===");

            toCustomer_before2({ id: this.id_ }).then((res) => {
              // console.log(res.data);
              
              console.log( res.data.data.code,"===发送第二个请求,获取到code===");
              this.code_ = res.data.data.code;
              console.log(this.code_, "===this.code_==");
              this.form.code = this.code_;
              console.log(this.form.code, "===this.form.code==");

            })

            })
  },


    /** 查询客户列表 */
    getList() {
      this.loading = true;
      listCustomer(this.queryParams).then((response) => {
        console.log(response,'response');
        
        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        name: null,
        linkman: null,
        phone: null,
        region: null,
        customerIndustry: null,
        customerRank: null,
        customerStatus: null,
        status: '0',
        cluesName: null,
        cluesSource: null,
        cluesStatus: null,
        dealStatus: '0',
        owner: null,
        delFlag: null,
        version: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        url:null
      };
      this.resetForm("form");
    },

    //选择文件
    handleUpload() {
      this.$refs.fileInput.click();
    },
    // 营业执照上传
    handleUploadBusinessLicense() {
      this.$refs.fileInputBusinessLicense.click();
    },
    // 处理文件选择
    handleFileChange(event) {
      const file = event.target.files[0];
      console.log(file, "==file==");

      if (!file) {
        return;
      }

      // 创建FormData对象
      const formData = new FormData();
      formData.append("file", file);
      const fileName = file.name;
      // const fileName = "group1/dfs/20250326113456072.设备产量明细表.png";
      reqFileUpload(fileName, formData).then(
        (response) => {
          console.log(this.form.url, "==老this.form.url==");
          this.form.url = response.data.data;
          console.log(this.form.url, "==新上传的this.form.url==");

          this.$message({
            type: "success",
            message: `上传成功!`,
            
          });
        },
        (error) => {
          this.$message.error("上传失败");
        }
      );
    },

    handleFileChangeBusinessLicense(event) {
      const file = event.target.files[0];
      console.log(file, "==file==");

      if (!file) {
        return;
      }
      const formData = new FormData();
      formData.append("file", file);
      const fileName = file.name;

      reqFileUpload(fileName, formData)
        .then((response) => {
          console.log(this.form.businessLicense, "==老this.form.businessLicense==");
          this.form.businessLicense = response.data.data;
          console.log(this.form.businessLicense, "==新上传的this.form.businessLicense==");

          this.$message({
            type: "success",
            message: `营业执照上传成功!`,
          });
        })
        .catch((error) => {
          this.$message.error("营业执照上传失败");
        });
    },
    handledownload_(event) {
      event.preventDefault();
      this.handledownload();
    },
    //下载模板
    handledownload() {
  this.$confirm("即将导出当前内容?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      console.log(this.form.url, "this.form.url");
      if (this.form.url == null) {
        console.log(this.form.url, "this.form.url");
        let res = await handledownloadApi();
        console.log(res, "===res===");
        if (res.status == 200) {
          let url = window.URL.createObjectURL(
            new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
          );
          const aLink = document.createElement("a");
          aLink.href = url;
          let timestamp = new Date().getTime();
          aLink.setAttribute("download", "客户定期评估表" + timestamp);
          document.body.appendChild(aLink);
          aLink.click();
          document.body.removeChild(aLink);
          this.$message({
            type: "success",
            message: "导出成功!",
          });
          console.log("导出成功");
        } else {
          this.$message({
            type: "error",
            message: "导出失败，请重试",
          });
          console.log("导出失败，请重试");
        }
      } 
      else {
        console.log(this.form.url, "this.form.url");
        console.log(this.Row, "==this.Row==");
        let res = await reqFileDownload(this.form.url);
        console.log(res, "===res===");
        if (res.status == 200) {
          let url = window.URL.createObjectURL(
            new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
          );
          const aLink = document.createElement("a");
          aLink.href = url;
          let timestamp = new Date().getTime();
          aLink.setAttribute("download", "客户定期评估表" + timestamp);
          document.body.appendChild(aLink);
          aLink.click();
          document.body.removeChild(aLink);
          this.$message({
            type: "success",
            message: "导出成功!",
          });
          console.log("导出成功");
        } else {
          this.$message({
            type: "error",
            message: "导出失败，请重试",
          });
          console.log("导出失败，请重试");
        }

        // addCustomer(this.form).then((response) => {
        //       console.log(response, "==response新增文件修改==");

        //       this.$modal.msgSuccess("新增文件修改成功");
        //       this.open = false;
        //       this.getList();
        //     });

      }
    })
    .catch(() => {
      console.log(this.form.url, "this.form.url");
      this.$message({ type: "info", message: "取消导出" });
    });
},
    handledownload_yingye(event) {
          event.preventDefault();
          this.handledownload_yingye_();
   },

        //下载营业执照
        handledownload_yingye_() {
      this.$confirm("即将导出当前内容?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          console.log(this.form.businessLicense, "this.form.businessLicense");

          console.log(this.Row, "==this.Row==");
          let res = await reqFileDownload(this.form.businessLicense);
          console.log(res, "===res===");
          if (res.status == 200) {
            let url = window.URL.createObjectURL(
              new Blob([res.data], {
                type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
              })
            );
            const aLink = document.createElement("a");
            aLink.href = url;
            let timestamp = new Date().getTime();
            aLink.setAttribute("download", "营业执照" + timestamp);
            document.body.appendChild(aLink);
            aLink.click();
            document.body.removeChild(aLink);
            this.$message({
              type: "success",
              message: "导出成功!",
            });
            console.log("导出成功");
          } else {
            this.$message({
              type: "error",
              message: "导出失败，请重试",
            });
            console.log("导出失败，请重试");
          }
        })
        .catch(() => {
          this.$message({ type: "info", message: "取消导出" });
        });
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.selected = selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户";
      this.getcuscode()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {


getreview(this.username).then(res=>{
  if(res.code==200){
    console.log(res.data,'==res.data==');
    this.id_guanli=res.data
  }
  
})


      this.Row=row
      console.log(row, "==row==");
      this.reset();
      const id = row.id || this.ids;
      getCustomer(id).then((response) => {
        if (
          response.data.headOfficeControl === null ||
          response.data.headOfficeControl === "false"
        ) {
          response.data.headOfficeControl = false;
        }
        if (response.data.headOfficeControl === "true") {
          response.data.headOfficeControl = true;
        }
        this.form = response.data;
        this.form.region = this.form.region.split(",");
        this.open = true;
        this.title = "修改客户";
      });
    },


    //详情
    handleUpdate_(row) {


getreview(this.username).then(res=>{
  if(res.code==200){
    console.log(res.data,'==res.data==');
    this.id_guanli=res.data
  }
  
})


      this.Row=row
      console.log(row, "==row==");
      this.reset();
      const id = row.id || this.ids;
      getCustomer(id).then((response) => {
        if (
          response.data.headOfficeControl === null ||
          response.data.headOfficeControl === "false"
        ) {
          response.data.headOfficeControl = false;
        }
        if (response.data.headOfficeControl === "true") {
          response.data.headOfficeControl = true;
        }
        this.form = response.data;
        this.form.region = this.form.region.split(",");
        this.open = true;
        this.title = "详情";
      });
    },





       //审核按钮



       review() {
      if(this.form.toExamine=='审核'||this.form.toExamine==null){

        
        this.$confirm('审核过了吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
this.form.toExamine='已审核'

        }).catch(() => {
       
        });

}
else if (this.form.toExamine == '已审核') {
      this.$message.success("已经审核过了");
    }
},



//弹窗确定按钮
    submitForm(t) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.region) {
            this.form.region = this.form.region.join(",");
          }
          if (this.form.id != null) {
            this.form.owner = this.userList.find(val => val.userName == this.form.userName)?.nickName || "";
            this.form.userName = this.form.userName;
            updateCustomer(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            // console.log(this.form,'==this.form==');
            // return;
            this.form.owner = this.userList.find(val => val.userName == this.form.userName)?.nickName || "";
            this.form.userName = this.form.userName;
            
            // alert('新增 无id')
            addCustomer(this.form).then((response) => {
              console.log(response, "==response新增==");

              if (response.code == 200) {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.$message.error("新增的客户编号重复");
                return false;
              }
            });
          }
        } else {
          this.$message.error("必填项需要填完整");
          return false;
        }
      });
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除客户编号为"' + ids + '"的数据项？')
        .then(function () {
          return delCustomer(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport_(event) {
      event.preventDefault();
      this.handleExport();
    },


   async handleExport() {
//
                const Authorization = 'Bearer' + 
            (localStorage.getItem('Token')||'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJmQm9wV2otVTFIYjlTa0ZHMHZYQ1lRVVhkRkdDMGhXRTBkVjJCN1FaSl9ZIn0.eyJleHAiOjE3NTExNzk5NzMsImlhdCI6MTc0NTk5NTk3MywianRpIjoiOGQ5YWEyY2MtMTI4Mi00OGZmLTg5ZjctNTY3ZGZiMjRkYWQyIiwiaXNzIjoiaHR0cDovLzE3Mi4xNi4wLjM6ODQxMS9hdXRoL3JlYWxtcy9lZGdlIiwiYXVkIjpbIm5vY29jb25zb2xlIiwiYWNjb3VudCIsIm9jcy1jb250cm9sbGVyIl0sInN1YiI6ImIwMjZiYzUxLTEzMjItNDJiOC1iZTg0LWU5MDJiNmFjYmM3YSIsInR5cCI6IkJlYXJlciIsImF6cCI6Imppbmd6aGkiLCJzZXNzaW9uX3N0YXRlIjoiMzgyZmFiNTktYWI0ZC00ZTZjLWJkNWMtNTNlZDIzYzM0ZDUwIiwiYWNyIjoiMSIsInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyLnsr7liLYt57O757uf566h55CG5ZGYIiwi57O757uf6L-Q57u0Iiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsImRlZmF1bHQtcm9sZXMtZWRnZSJdfSwicmVzb3VyY2VfYWNjZXNzIjp7Im5vY29jb25zb2xlIjp7InJvbGVzIjpbIm5vY29fY29uc29sZV9hZG1pbl9yb2xlIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX0sIm9jcy1jb250cm9sbGVyIjp7InJvbGVzIjpbIm9jcy1jb250cm9sbGVyLWFkbWluLXJvbGUiLCJvY3MtY29udHJvbGxlci1yZWFkLXJvbGUiXX19LCJzY29wZSI6InByb2ZpbGUgZW1haWwiLCJzaWQiOiIzODJmYWI1OS1hYjRkLTRlNmMtYmQ1Yy01M2VkMjNjMzRkNTAiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5hbWUiOiLmm77kuL3okI0iLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ6ZW5nbHAiLCJnaXZlbl9uYW1lIjoi5pu-5Li96JCNIiwiZW1haWwiOiJ6ZW5nbHBAdGVzdC5jb20ifQ.BZ3FgWEKPTSZSc60sbf7u0dDGs5TiCZ6DOWMW4RLC16abjIS6ySYgLhRx_JAhKXmJjyk8DkrBu0lBs1mNy4lOJdkzkjzQ3CUDbt6xUodjCTxJJ0tAJF6DFdbh8g49QmHOZFkjszw9qzn6H_7b8HbD5Bv1JTv1LUOXvdmEu7whtUZOay3EX0UeqBFGhd4MmgYufr8r5rPoM4tp8haEz_kXWf_N_6o4XmpzqFvSwEOwg1QI6eiZaQpoEQLJq1skCOxFOAYHKZXA2AdbX0vB3W4UGT-ovwUJRV64OFv3AH8Tu59isgEmCSghgpbsxJZ96pAFYc0v_CgHFUZkIT2ngp3dQ')
        const url = localStorage.getItem('wsAddress')?.replace('wss://', 'https://');
        axios({
          url: url + '/factory/v1/jy-crm-app/crm/customer/export2', 
          // url:'http://192.168.1.14:20910/crm/customer/export2',
          method: 'post', 
          responseType: 'blob',
          headers: {
            Authorization
          }
        }).then(response => {
          // 请求成功，处理响应数据
          const url = window.URL.createObjectURL(new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })); // 创建一个Blob对象，并生成一个URL
          const link = document.createElement('a'); // 创建一个临时的<a>标签用于下载
          link.href = url; // 设置<a>标签的href属性为Blob对象的URL
          link.setAttribute('download', '客户列表.xlsx'); // 设置下载文件名，扩展名根据实际文件类型设置
          document.body.appendChild(link); // 将<a>标签添加到页面中，以便可以点击
          link.click(); // 模拟点击<a>标签，触发下载
          document.body.removeChild(link); // 下载触发后，从页面中移除<a>标签
          window.URL.revokeObjectURL(url); // 释放创建的URL对象，避免内存泄漏
        }).catch(error => {
          // 请求失败，处理错误
          console.error('下载文件失败:', error);
          alert('下载文件失败，请稍后重试或联系管理员');
        });

      },

    
    handleTransfer(row) {
      const ids = row.id || this.ids.join(",");
      this.transferCustomer = true;
      this.$nextTick(() => {
        this.$refs.transferCustomer.open(ids);
      });
    },
    handleTransferCustomerClose() {
      this.transferCustomer = false;
      this.getList();
    },
    handleToPool(row) {
      const ids = row.id || this.ids.join(",");
      this.toPool = true;
      this.$nextTick(() => {
        this.$refs.toPool.open(ids);
      });
    },
    handleToPoolClose() {
      this.toPool = false;
      this.getList();
    },

    handleComment(row) {
      const id = row.id;
      this.commentCustomer = true;
      this.$nextTick(() => {
        this.$refs.commentCustomer.open(id);
      });
    },
    handleCommentClose() {
      this.commentCustomer = false;
      this.getList();
    },
    provincesValueChang(value) {
      this.form.region = value;
    },

    //获取负责人列表信息
    getUserList() {
      reqUserList()
        .then((response) => {
          if (response.code === 200) {
            const tmp = response.data;
            this.userList = tmp;
          }
          console.log("获取负责人列表信息", response);
        })
        .catch((error) => {
          console.log("获取负责人列表信息", error);
        });
    },

    //tabs切换操作
    handleClick(tab, event) {
      console.log(tab, event);
    },
  },
};
</script>
